/*
 * @Author: Joel
 * @Date: 2025-06-29 15:19:45
 * @LastEditors: Joel
 * @LastEditTime: 2025-06-30 08:58:57
 * @FilePath: /a94b114frn/src/delay.c
 * @Description: 
 * Copyright (C) 2025 HTI DongGuan Ltd., All Rights Reserved. 
 * 2025-06-29 15:19:45
 */

/* Includes ------------------------------------------------------------------*/
#include    "typedef.h"
#include    "delay.h"       //
/* Private Pre-processor Definition & Macro ----------------------------------*/
/* Private Typedef -----------------------------------------------------------*/
/* Private Variable ----------------------------------------------------------*/
/* Private Function Prototype ------------------------------------------------*/
/* Public Variable -----------------------------------------------------------*/
/* Public Function -----------------------------------------------------------*/
/***************************************************************************//**
* @brief    System NOP 1us Delay rountine. (MCLK = 16MHZ)
* @note     1 machine cycle comprises 1 system clock cycles. (@ABOV 94 Core Serise)
*           16 system clock delay
* @param    None
* @return   None
*******************************************************************************/
volatile void delay_us(unsigned int us){
    uint16_t i;
    do{
        i = MAIN_Fosc / 13000000; //(附：主频需要大于13MHz）
    while(--i) ; //14T per loop
    }while(--us);
}
/***************************************************************************//**
* @brief    System NOP 10us Delay rountine. (MCLK = 16MHZ)
* @note     1 machine cycle comprises 1 system clock cycles. (@ABOV 94 Core Serise)
*           160 system clock delay
*           1 machine cycle can be added depending on code optimization.
*
*           ex1)    MOV R7,#(Low byte of delay)
*                   MOV R6,#(high byte of delay)
*                   LCALL   delay_ms
*
*           ex2)    MOV A,#(Low byte of delay) // Lower byte and higher byte are the same.
*                   MOV R7,A
*                   MOV R6,A
*                   LCALL   delay_ms
*
* @param    delay : unsigned int 1~65,355 (delay) * 10us (@System clock = 16Mhz)
* @return   None
*******************************************************************************/
volatile void delay_ms(unsigned int delay)
{
    u16 i;
    do{
        i = MAIN_Fosc / 13000;
    while(--i) ; //14T per loop
    }while(--delay);
}
/* --------------------------------- End Of File ------------------------------ */
